home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
Issue61
/
BHO
/
uInfoBHO.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2000-07-07
|
7KB
|
207 lines
unit uInfoBHO;
interface
uses
ComObj, ActiveX, pSimpleBHO_TLB, StdVcl, SHDocVW, Windows, SysUtils, Dialogs,
uBHOManager;
const DISPID_BEFORENAVIGATE2 = 250;
const DISPID_NAVIGATECOMPLETE2 = 252;
type
TInfoBHO = class(TAutoObject, IInfoBHO, IObjectWithSite, IDispatch)
private
BHOManager : TfrmBHOManager;
function AdviseEvents : boolean;
function GetParameterTypeAsString( varType : TVarType ) : String;
protected
WebBrowser : IWebBrowser2;
public
procedure Initialize; override;
// Explorer releated methods.
function SetSite(const pUnkSite: IUnknown ):HResult; stdcall;
function GetSite(const riid: TIID; out site: IUnknown):HResult; stdcall;
function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; stdcall;
end;
implementation
uses ComServ;
// Private methods for the TInfoBHO class.
function TInfoBHO.GetParameterTypeAsString( varType : TVarType ) : String;
begin
case varType of
VT_UI1: Result := 'VT_UI1';
VT_I2: Result := 'VT_I2';
VT_I4: Result := 'VT_I4';
VT_R4: Result := 'VT_R4';
VT_R8: Result := 'VT_R8';
VT_BOOL: Result := 'VT_BOOL';
VT_ERROR: Result := 'VT_ERROR';
VT_CY: Result := 'VT_CY';
VT_DATE: Result := 'VT_DATE';
VT_BSTR: Result := 'VT_BSTR';
VT_UNKNOWN: Result := 'VT_UNKNOWN';
VT_DISPATCH: Result := 'VT_DISPATCH';
VT_ARRAY: Result := 'VT_ARRAY';
VT_BYREF or VT_UI1: Result := 'VT_BYREF or VT_UI1';
VT_BYREF or VT_I2: Result := 'VT_BYREF or VT_I2';
VT_BYREF or VT_I4: Result := 'VT_BYREF or VT_I4';
VT_BYREF or VT_R4: Result := 'VT_BYREF or VT_R4';
VT_BYREF or VT_R8: Result := 'VT_BYREF or VT_R8';
VT_BYREF or VT_BOOL: Result := 'VT_BYREF or VT_BOOL';
VT_BYREF or VT_ERROR: Result := 'VT_BYREF or VT_ERROR';
VT_BYREF or VT_CY: Result := 'VT_BYREF or VT_CY';
VT_BYREF or VT_DATE: Result := 'VT_BYREF or VT_DATE';
VT_BYREF or VT_BSTR: Result := 'VT_BYREF or VT_BSTR';
VT_BYREF or VT_UNKNOWN: Result := 'VT_BYREF or VT_UNKNOWN';
VT_BYREF or VT_DISPATCH: Result := 'VT_BYREF or VT_DISPATCH';
VT_BYREF or VT_ARRAY: Result := 'VT_BYREF or VT_ARRAY';
VT_BYREF or VT_VARIANT: Result := 'VT_BYREF or VT_VARIANT';
VT_BYREF: Result := 'VT_BYREF';
VT_I1: Result := 'VT_I1';
VT_UI2: Result := 'VT_UI2';
VT_UI4: Result := 'VT_UI4';
VT_INT: Result := 'VT_INT';
VT_UINT: Result := 'VT_UINT';
VT_BYREF or VT_DECIMAL: Result := 'VT_BYREF or VT_DECIMAL';
VT_BYREF or VT_I1: Result := 'VT_BYREF or VT_I1';
VT_BYREF or VT_UI2: Result := 'VT_BYREF or VT_UI2';
VT_BYREF or VT_UI4: Result := 'VT_BYREF or VT_UI4';
VT_BYREF or VT_INT: Result := 'VT_BYREF or VT_INT';
VT_BYREF or VT_UINT: Result := 'VT_BYREF or VT_UINT';
end;
end;
// Advise events to listen for browser events.
function TInfoBHO.AdviseEvents : boolean;
var
ConnectionPoints : IConnectionPointContainer;
WebEvents : IConnectionPoint;
Hr : HResult;
dwCookie : Integer;
begin
ConnectionPoints := WebBrowser as IConnectionPointContainer;
Hr := ConnectionPoints.FindConnectionPoint( DIID_DWebBrowserEvents2, WebEvents );
WebEvents.Advise( self as IDispatch, dwCookie );
Result := true;
end;
// Create the BHO manager form.
procedure TInfoBHO.Initialize;
begin
BHOManager := TfrmBHOManager.Create( nil );
BHOManager.Show;
end;
// SetSite method
function TInfoBHO.SetSite(const pUnkSite: IUnknown ):HResult;
begin
if ( pUnkSite <> Nil ) then
begin
WebBrowser := pUnkSite as IWebBrowser2;
AdviseEvents;
end;
Result := S_OK;
end;
function TInfoBHO.GetSite(const riid: TIID; out site: IUnknown):HResult;
begin
Result := S_OK;
end;
// The Invoke method - where all the fun takes place.
function TInfoBHO.Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult;
var
DispParams : TDispParams;
VarArg : TVariantArg;
varType : TVarType;
WebAsVariant : PVariant;
CurrentWebBrowser : IWebBrowser2;
PostData, TargetFrame, NavigateToUrl : String;
begin
try
DispParams := TDispParams(Params);
case DispID of
// [0]: Cancel flag - VT_BYREF|VT_BOOL
// [1]: HTTP headers - VT_BYREF|VT_VARIANT
// [2]: Address of HTTP POST data - VT_BYREF|VT_VARIANT
// [3]: Target frame name - VT_BYREF|VT_VARIANT
// [4]: Option flags - VT_BYREF|VT_VARIANT
// [5]: URL to navigate to - VT_BYREF|VT_VARIANT
// [6]: An object that evaluates to the top-level or frame
// WebBrowser object corresponding to the event.
DISPID_BEFORENAVIGATE2 :
begin
// Get current IWebBrowser2 interface.
VarArg := DispParams.rgvarg^[6];
CurrentWebBrowser := IDispatch(VarArg.dispVal) as IWebBrowser2;
varType := VarArg.vt;
GetParameterTypeAsString( varType );
// Get PostData information.
VarArg := DispParams.rgvarg^[2];
PostData := VarArg.pvarVal^;
// Get Target frame name.
VarArg := DispParams.rgvarg^[3];
TargetFrame := VarArg.pvarVal^;
// Get NavigateTo url.
VarArg := DispParams.rgvarg^[5];
NavigateToUrl := VarArg.pvarVal^;
if ( Assigned( BHOManager ) ) then
begin
BHOManager.SetWebBrowser( CurrentWebBrowser );
if ( CurrentWebBrowser = WebBrowser ) then
BHOManager.AddLogLine( 'BeforeNavigate2 - TopWindow' )
else
BHOManager.AddLogLine( 'BeforeNavigate2 - FrameWindow' );
end;
end;
// [0]: URL navigated to - VT_BYREF|VT_VARIANT
// [1]: An object that evaluates to the top-level or frame
// WebBrowser object corresponding to the event.
DISPID_NAVIGATECOMPLETE2 :
begin
// Get current IWebBrowser2 interface.
VarArg := DispParams.rgvarg^[1];
CurrentWebBrowser := IDispatch(VarArg.dispVal) as IWebBrowser2;
// Get URL navigated to.
VarArg := DispParams.rgvarg^[0];
NavigateToUrl := VarArg.pvarVal^;
if ( Assigned( BHOManager ) ) then
begin
if ( CurrentWebBrowser = WebBrowser ) then
BHOManager.AddLogLine( 'NavigateComplete2 - TopWindow' )
else
BHOManager.AddLogLine( 'NavigateComplete2 - FrameWindow' );
end;
end;
end;
finally
Result := S_OK;
end;
end;
initialization
TAutoObjectFactory.Create(ComServer, TInfoBHO, Class_InfoBHO,
ciMultiInstance, tmApartment);
end.